﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Public;
using BLL;

namespace QLNhanKhau
{
    public partial class frmChiTietChuyenKhau : Form
    {
        int _MaNK;
        public frmChiTietChuyenKhau()
        {
            InitializeComponent();
        }
        public frmChiTietChuyenKhau(int MaNK)
        {
            InitializeComponent();
            this._MaNK = MaNK;
        }

        private void frmChiTietChuyenKhau_Load(object sender, EventArgs e)
        {
            ThietLapPublic tl = ThietLapBLL.LoadThietLapByMaNK(_MaNK);
            List<ChuyenKhauPublic> list_ck = ChuyenKhauBLL.LoadChuyenKhauByMaNK(_MaNK,tl.TenServer,tl.TenData);
            if (list_ck.Count != 0)
            {
                dgvChuyenKhau.DataSource = list_ck;
                //dgvChuyenKhau.Columns[0].HeaderText = "Mã chuyển khẩu";
                //dgvChuyenKhau.Columns[1].HeaderText = "Mã nhân khẩu";
                dgvChuyenKhau.Columns[2].HeaderText = "Số";
                //dgvChuyenKhau.Columns[3].HeaderText = "Số sổ hộ khẩu";
                dgvChuyenKhau.Columns[4].HeaderText = "Nơi chuyển";
                dgvChuyenKhau.Columns[5].HeaderText = "Lý do chuyển";
                //dgvChuyenKhau.Columns[6].HeaderText = "Ngày cấp";
                //dgvChuyenKhau.Columns[7].HeaderText = "Cán bộ nơi chuyển";
                dgvChuyenKhau.Columns[8].HeaderText = "Người cấp";
                //dgvChuyenKhau.Columns[9].HeaderText = "Chức vụ người chuyển";
                dgvChuyenKhau.Columns[10].HeaderText = "Nơi cấp";
                // dgvChuyenKhau.Columns[11].HeaderText = "Cán bộ nơi nhận";
                //dgvChuyenKhau.Columns[12].HeaderText = "Ngày nhận";
                dgvChuyenKhau.Columns[13].HeaderText = "Người nhận";
                // dgvChuyenKhau.Columns[14].HeaderText = "Chức vụ người nhận";
                //dgvChuyenKhau.Columns[15].HeaderText = "Nơi ở trước";
                dgvChuyenKhau.Columns[16].HeaderText = "Chủ hộ";
                dgvChuyenKhau.Columns[17].HeaderText = "Quan hệ";
                dgvChuyenKhau.Columns[0].Visible = false;
                dgvChuyenKhau.Columns[1].Visible = false;
                //dgvChuyenKhau.Columns[2].Visible = false;
                dgvChuyenKhau.Columns[3].Visible = false;
                //dgvChuyenKhau.Columns[4].Visible = false;
                //dgvChuyenKhau.Columns[5].Visible = false;
                dgvChuyenKhau.Columns[6].Visible = false;
                dgvChuyenKhau.Columns[7].Visible = false;
                dgvChuyenKhau.Columns[8].Visible = false;
                dgvChuyenKhau.Columns[9].Visible = false;
                //dgvChuyenKhau.Columns[10].Visible = false;
                dgvChuyenKhau.Columns[11].Visible = false;
                dgvChuyenKhau.Columns[12].Visible = false;
                dgvChuyenKhau.Columns[13].Visible = false;
                dgvChuyenKhau.Columns[14].Visible = false;
                dgvChuyenKhau.Columns[15].Visible = false;
                dgvChuyenKhau.Columns[16].Visible = false;
                //dgvChuyenKhau.Columns[16].Visible = false;
                
            }
            else
            {
                dgvChuyenKhau.DataSource = null;
                
            }
        }

        private void dgvChuyenKhau_SelectionChanged(object sender, EventArgs e)
        {
            
            DataGridViewCell cell = null;

            foreach (DataGridViewCell select in dgvChuyenKhau.SelectedCells)
            {
                cell = select;
            }
            if (cell != null)
            {
                DataGridViewRow row = cell.OwningRow;
                NhanKhauPublic nk = NhanKhauBLL.LoadNhanKhauByMaNK(_MaNK);
                txtHoTen.Text = nk.HoTen;
                if (nk.GioiTinh == true)
                    sbtGioiTinh.Value = true;
                else
                    sbtGioiTinh.Value = false;
                txtDanToc.Text = DanTocBLL.LoadDanTocByMaDT(nk.MaDT).TenDanToc;
                txtQuocTich.Text = QuocTichBLL.LoadQuocTichByMaQT(nk.MaQT).TenQuocTich;
                txtTonGiao.Text = TonGiaoBLL.LoadTonGiaoByMaTG(nk.MaTG).TenTonGiao;
                txtTenGoiKhac.Text = nk.TenGoiKhac;
                txtCMND.Text = nk.CMND;
                txtThuongTru.Text = SoHoKhauBLL.LoadDiaChiSHKByMaNK(nk.MaNK) + ThietLapBLL.LoadTenPhuongXa();
                txtNoiChuyen.Text = ThietLapBLL.LoadDiaChiByMaDiaChi((int)row.Cells[4].Value);
                txtNoiCap.Text = ThietLapBLL.LoadDiaChiByMaDiaChi((int)row.Cells[10].Value);

                //if (row.Cells[4].Value.ToString().Length > 6)
                //    txtDen.Text = row.Cells[4].Value.ToString();
                //else
                //    txtDen.Text = ThietLapBLL.LoadDiaChiByMaDiaChi((int)row.Cells[4].Value);
                
                dateNgayCap.Value = (DateTime)row.Cells[6].Value;
                txtLyDoChuyen.Text = row.Cells[5].Value.ToString();
                //txtChuyenTu.Text=row.Cells[].Value;
                txtSoChuyenKhau.Text = row.Cells[2].Value.ToString();

            }
        }

        private void btnXong_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        //
    }
}
